from typing import List


class Solution:
    def maximumEnergy(self, energy: List[int], k: int) -> int:
        n = len(energy)
        ans = -float('inf')
        for i in range(k):
            j = n - 1 - i
            max_val = energy[j]
            ans = max(max_val, ans)
            j -= k
            while j >= 0:
                max_val += energy[j]
                j -= k
                ans = max(max_val, ans)
        return ans

if __name__ == '__main__':
    s = Solution()
    r = s.maximumEnergy([8,-5],1)
    print(r)
